<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta http-equiv="Cache-Control" content="no-siteapp">
  <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no">
  <meta name="renderer" content="webkit">

  
  <title>Android 14 截屏流程解析 | 龙之叶的博客</title>

  <link rel="shortcut icon" href="/images/favicon.png">
  <link rel="alternate" href="/atom.xml" title="龙之叶的博客" type="application/atom+xml">
  <meta name="description" content="Android 14 截屏流程解析">
<meta property="og:type" content="article">
<meta property="og:title" content="Android 14 截屏流程解析">
<meta property="og:url" content="http://longzhiye.top/2024/02/10/2024-02-10/index.html">
<meta property="og:site_name" content="龙之叶的博客">
<meta property="og:description" content="Android 14 截屏流程解析">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2024-02-09T16:00:00.000Z">
<meta property="article:modified_time" content="2024-08-29T02:40:34.921Z">
<meta property="article:author" content="龙之叶">
<meta property="article:tag" content="Android">
<meta property="article:tag" content="SystemUI">
<meta property="article:tag" content="framework">
<meta name="twitter:card" content="summary">

  <meta name="keywords" content=",Android,SystemUI,framework">
  <meta name="format-detection" content="telephone=no,email=no">
  <meta name="theme-color" content="#9C27B0">

  <meta name="mobile-web-app-capable" content="yes">
  <meta name="application-name" content="龙之叶的博客">
  <meta name="msapplication-starturl" content="http://longzhiye.top/2024/02/10/2024-02-10/">
  <meta name="msapplication-navbutton-color" content="#9C27B0">
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="apple-mobile-web-app-title" content="龙之叶的博客">
  <meta name="apple-mobile-web-app-status-bar-style" content="black">
  <link rel="apple-touch-icon" href="/images/favicon.png">

  
    <link rel="canonical" href="http://longzhiye.top/2024/02/10/2024-02-10/">
  

  
  

  
  
  

  
<link rel="stylesheet" href="/css/mdui.css">
<link rel="stylesheet" href="/css/style.css">

  
<link rel="stylesheet" href="/custom.css">

<meta name="generator" content="Hexo 5.4.2"></head>

<body class="mdui-appbar-with-toolbar mdui-theme-primary-indigo mdui-theme-accent-pink">
  <script>var a=localStorage.getItem("mdui-theme-layout-dark");if(a){document.getElementsByTagName("body")[0].className+=" mdui-theme-layout-dark"};</script>
  <script>if(window.matchMedia&&window.matchMedia("(prefers-color-scheme: dark)").matches){document.getElementsByTagName("body")[0].className+=" mdui-theme-layout-dark"};</script>
  <script>var a=localStorage.getItem("mdui-drawer-close");if(!a){document.getElementsByTagName("body")[0].className+=" mdui-drawer-body-left"};</script>
  <header id="header" class="mdui-appbar mdui-appbar-fixed mdui-appbar-scroll-hide mdui-appbar-inset">
  <div class="mdui-toolbar mdui-color-theme">
    <a href="javascript:;" class="mdui-btn mdui-btn-icon" mdui-drawer="{target: '#sidebar', swipe: true}"><i class="mdui-icon material-icons">menu</i></a>
    <a href="/" class="mdui-typo-headline">龙之叶的博客</a>
    <div class="mdui-toolbar-spacer"></div>
    <a href="javascript:;" class="mdui-btn mdui-btn-icon" mdui-dialog="{target: '#search'}" mdui-tooltip="{content: '搜索'}"><i class="mdui-icon material-icons">search</i></a>
	<!--
    <a href="/atom.xml" class="mdui-btn mdui-btn-icon" mdui-tooltip="{content: 'RSS'}"><i class="mdui-icon material-icons">rss_feed</i></a>
	-->
  </div>
</header>
<div class="mdui-dialog" id="search">
  
    <div class="search-form">
      <input type="search" class="search-form-input" placeholder="请输入关键字">
    </div>
    <div class="search-result" data-resource="/search.xml"></div>
  
</div>

  <aside id="sidebar" class="mdui-drawer mdui-drawer-full-height">
  <script>var a=localStorage.getItem("mdui-drawer-close");if(a){document.getElementById("sidebar").className+=" mdui-drawer-close"};</script>
  <div class="mdui-grid-tile">
    <img src="/images/banner.png" style="height: 160px;">
    <img src="/images/avatar.png" class="avatar-animation" style="position: absolute; top: 10%; left: 24px; width: 64px; height: 64px; border: 2px solid #fff; border-radius: 50%;background-color:#fff;">
    <div class="mdui-grid-tile-actions">
      <div class="mdui-grid-tile-text">
        <div class="mdui-grid-tile-title">龙之叶</div>
        <div class="mdui-grid-tile-subtitle"><i class="mdui-icon material-icons">art_track</i>生命不息，折腾不止</div>
      </div>
      
        <div class="mdui-grid-tile-buttons">
          <a href="mailto:longzhiye163@163.com" class="mdui-btn mdui-btn-icon" mdui-tooltip="{content: 'longzhiye163@163.com'}"><i class="mdui-icon material-icons">email</i></a>
        </div>
      
    </div>
  </div>

  <div class="mdui-list" mdui-collapse="{accordion: true}">
    <a href="/" class="mdui-list-item mdui-ripple">
      <i class="mdui-list-item-icon mdui-icon material-icons mdui-text-color-blue">home</i>
      <div class="mdui-list-item-content">主页</div>
    </a>
    <div class="mdui-collapse-item">
      <script>var a=localStorage.getItem("mdui-collapse-item-0");if(a){document.getElementsByClassName("mdui-collapse-item")[0].className+=" mdui-collapse-item-open"};</script>
      <div class="mdui-collapse-item-header mdui-list-item mdui-ripple">
        <i class="mdui-list-item-icon mdui-icon material-icons mdui-text-color-deep-orange">archive</i>
        <div class="mdui-list-item-content">归档</div>
        <i class="mdui-collapse-item-arrow mdui-icon material-icons">keyboard_arrow_down</i>
      </div>
      <div class="mdui-collapse-item-body mdui-list mdui-list-dense">
        
        <a class="mdui-ripple sidebar_archives-link" href="/archives/2025/07/">七月 2025<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2025/06/">六月 2025<span class="mdui-ripple sidebar_archives-count">2</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2025/03/">三月 2025<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2025/02/">二月 2025<span class="mdui-ripple sidebar_archives-count">2</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2025/01/">一月 2025<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2024/10/">十月 2024<span class="mdui-ripple sidebar_archives-count">7</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2024/09/">九月 2024<span class="mdui-ripple sidebar_archives-count">4</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2024/08/">八月 2024<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2024/03/">三月 2024<span class="mdui-ripple sidebar_archives-count">5</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2024/02/">二月 2024<span class="mdui-ripple sidebar_archives-count">11</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2024/01/">一月 2024<span class="mdui-ripple sidebar_archives-count">9</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2023/12/">十二月 2023<span class="mdui-ripple sidebar_archives-count">10</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2023/11/">十一月 2023<span class="mdui-ripple sidebar_archives-count">8</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2023/10/">十月 2023<span class="mdui-ripple sidebar_archives-count">8</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2023/09/">九月 2023<span class="mdui-ripple sidebar_archives-count">3</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2023/08/">八月 2023<span class="mdui-ripple sidebar_archives-count">6</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2023/06/">六月 2023<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2023/05/">五月 2023<span class="mdui-ripple sidebar_archives-count">4</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2023/04/">四月 2023<span class="mdui-ripple sidebar_archives-count">2</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2023/03/">三月 2023<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2023/02/">二月 2023<span class="mdui-ripple sidebar_archives-count">2</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2022/09/">九月 2022<span class="mdui-ripple sidebar_archives-count">7</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2022/08/">八月 2022<span class="mdui-ripple sidebar_archives-count">4</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2017/04/">四月 2017<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2017/03/">三月 2017<span class="mdui-ripple sidebar_archives-count">2</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2017/02/">二月 2017<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2017/01/">一月 2017<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2016/12/">十二月 2016<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2016/11/">十一月 2016<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2016/10/">十月 2016<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2016/08/">八月 2016<span class="mdui-ripple sidebar_archives-count">1</span></a>
        
      </div>
    </div>
    <div class="mdui-collapse-item">
      <script>var a=localStorage.getItem("mdui-collapse-item-1");if(a){document.getElementsByClassName("mdui-collapse-item")[1].className+=" mdui-collapse-item-open"};</script>
      <div class="mdui-collapse-item-header mdui-list-item mdui-ripple">
        <i class="mdui-list-item-icon mdui-icon material-icons mdui-text-color-green">class</i>
        <div class="mdui-list-item-content">分类</div>
        <i class="mdui-collapse-item-arrow mdui-icon material-icons">keyboard_arrow_down</i>
      </div>
      <div class="mdui-collapse-item-body mdui-list mdui-list-dense">
        
        <a class="mdui-ripple sidebar_archives-link" href="/categories/%E6%8A%80%E6%9C%AF/">技术<span class="mdui-ripple sidebar_archives-count">98</span></a><a class="mdui-ripple sidebar_archives-link" href="/categories/%E7%94%9F%E6%B4%BB/">生活<span class="mdui-ripple sidebar_archives-count">3</span></a><a class="mdui-ripple sidebar_archives-link" href="/categories/%E8%B5%84%E8%AE%AF/">资讯<span class="mdui-ripple sidebar_archives-count">4</span></a><a class="mdui-ripple sidebar_archives-link" href="/categories/%E9%80%9A%E7%9F%A5/">通知<span class="mdui-ripple sidebar_archives-count">4</span></a>
        
      </div>
    </div>
    <div class="mdui-collapse-item">
      <script>var a=localStorage.getItem("mdui-collapse-item-2");if(a){document.getElementsByClassName("mdui-collapse-item")[2].className+=" mdui-collapse-item-open"};</script>
      <div class="mdui-collapse-item-header mdui-list-item mdui-ripple">
        <i class="mdui-list-item-icon mdui-icon material-icons mdui-text-color-brown">bookmark</i>
        <div class="mdui-list-item-content">标签</div>
        <i class="mdui-collapse-item-arrow mdui-icon material-icons">keyboard_arrow_down</i>
      </div>
      <div class="mdui-collapse-item-body mdui-list mdui-list-dense">
        
        <a class="mdui-ripple sidebar_archives-link" href="/tags/ANR/" rel="tag">ANR<span class="mdui-ripple sidebar_archives-count">2</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/APP/" rel="tag">APP<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Android/" rel="tag">Android<span class="mdui-ripple sidebar_archives-count">89</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Android12/" rel="tag">Android12<span class="mdui-ripple sidebar_archives-count">3</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Android13/" rel="tag">Android13<span class="mdui-ripple sidebar_archives-count">2</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Android14/" rel="tag">Android14<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/AndroidStudio/" rel="tag">AndroidStudio<span class="mdui-ripple sidebar_archives-count">3</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/AutoDraw/" rel="tag">AutoDraw<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Crash/" rel="tag">Crash<span class="mdui-ripple sidebar_archives-count">2</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Foxmail/" rel="tag">Foxmail<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Framework/" rel="tag">Framework<span class="mdui-ripple sidebar_archives-count">20</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/GPS%E8%BD%A8%E8%BF%B9%E5%9B%BE/" rel="tag">GPS轨迹图<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Git/" rel="tag">Git<span class="mdui-ripple sidebar_archives-count">2</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/GitHub/" rel="tag">GitHub<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Google/" rel="tag">Google<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Hexo/" rel="tag">Hexo<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Java/" rel="tag">Java<span class="mdui-ripple sidebar_archives-count">3</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Kernel/" rel="tag">Kernel<span class="mdui-ripple sidebar_archives-count">4</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Launcher/" rel="tag">Launcher<span class="mdui-ripple sidebar_archives-count">17</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Lib/" rel="tag">Lib<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Linux/" rel="tag">Linux<span class="mdui-ripple sidebar_archives-count">18</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Markdown/" rel="tag">Markdown<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Material-Design/" rel="tag">Material Design<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/OS-X/" rel="tag">OS X<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/OTA/" rel="tag">OTA<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/QuickTime/" rel="tag">QuickTime<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/SSH/" rel="tag">SSH<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Settings/" rel="tag">Settings<span class="mdui-ripple sidebar_archives-count">6</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/SystemUI/" rel="tag">SystemUI<span class="mdui-ripple sidebar_archives-count">19</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Ubuntu/" rel="tag">Ubuntu<span class="mdui-ripple sidebar_archives-count">7</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/WPS/" rel="tag">WPS<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Wifi/" rel="tag">Wifi<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/WindTerm/" rel="tag">WindTerm<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Windows/" rel="tag">Windows<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/androidmk/" rel="tag">androidmk<span class="mdui-ripple sidebar_archives-count">2</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/blog/" rel="tag">blog<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/build/" rel="tag">build<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/feel/" rel="tag">feel<span class="mdui-ripple sidebar_archives-count">2</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/framework/" rel="tag">framework<span class="mdui-ripple sidebar_archives-count">50</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/git/" rel="tag">git<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/inotify/" rel="tag">inotify<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/life/" rel="tag">life<span class="mdui-ripple sidebar_archives-count">2</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/ninja/" rel="tag">ninja<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/rsync/" rel="tag">rsync<span class="mdui-ripple sidebar_archives-count">2</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/standard/" rel="tag">standard<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/test/" rel="tag">test<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/%E4%BC%81%E4%B8%9A%E5%BE%AE%E4%BF%A1/" rel="tag">企业微信<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F/" rel="tag">操作系统<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/%E6%B5%8B%E8%AF%95/" rel="tag">测试<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/%E6%BA%90%E7%A0%81/" rel="tag">源码<span class="mdui-ripple sidebar_archives-count">3</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/%E7%94%9F%E6%B4%BB%E6%84%9F%E6%82%9F/" rel="tag">生活感悟<span class="mdui-ripple sidebar_archives-count">1</span></a>
        
      </div>
    </div>
    <a href="/about" class="mdui-list-item mdui-ripple">
      <i class="mdui-list-item-icon mdui-icon material-icons mdui-text-color-purple">person</i>
      <div class="mdui-list-item-content">关于</div>
    </a>
  </div>

  <div class="mdui-divider"></div>

  <div class="mdui-list" mdui-collapse="{accordion: true}">
    
      <a href="/timeline" class="mdui-list-item mdui-ripple">时间轴</a>
    
    <div class="mdui-collapse-item">
      <script>var a=localStorage.getItem("mdui-collapse-item-3");if(a){document.getElementsByClassName("mdui-collapse-item")[3].className+=" mdui-collapse-item-open"};</script>
      <div class="mdui-collapse-item-header mdui-list-item mdui-ripple">
        <div class="mdui-list-item-content">友情链接</div>
        <i class="mdui-list-item-icon mdui-icon material-icons">link</i>
      </div>
      <div class="mdui-collapse-item-body mdui-list mdui-list-dense">
        
          <a href="http://www.niemingzhao.top" target="_blank" class="mdui-list-item mdui-p-l-2 mdui-text-color-theme-accent mdui-ripple" style="justify-content: center;">聂明照的博客</a>
        
        
      </div>
    </div>
  </div>
</aside>

  <main id="main" class="mdui-m-t-5 fadeIn animated">
  
<link rel="stylesheet" href="//cdn.bootcdn.net/ajax/libs/fancybox/3.5.7/jquery.fancybox.min.css">

  <style>#main article .mdui-card-content .center-block{display:block!important;margin-right:auto!important;margin-left:auto!important}</style>
  <style>#main article .mdui-card-content .text-center{text-align:center!important}</style>
  <article class="mdui-card mdui-m-b-5">
    <header class="mdui-card-media">
      <img src="/images/random/material-2.png" style="max-height: 240px;">
      <div class="mdui-card-media-covered">
        <div class="mdui-card-primary">
          <div class="mdui-card-primary-title">Android 14 截屏流程解析</div>
          <div class="mdui-card-primary-subtitle"><i class="iconfont">&#xe697;</i> 2024-02-10 / <i class="iconfont">&#xe601;</i> 龙之叶 &nbsp;&nbsp; <span id="busuanzi_container_page_pv" style="display: none;"><i class="iconfont">&#xe7fd;</i> <span id="busuanzi_value_page_pv"></span></span></div>
        </div>
      </div>
      <div class="mdui-card-menu">
        
          <button class="mdui-btn mdui-btn-icon mdui-text-color-white" mdui-menu="{target: '#qrcode', align: 'right'}"><i class="mdui-icon material-icons">devices</i></button>
          <ul class="mdui-menu" id="qrcode">
            
              <li class="mdui-menu-item"><a class="mdui-text-center mdui-ripple">发送到手机</a></li>
            
            <li class="mdui-menu-item" disabled>
              
                <img src="//qr.liantu.com/api.php?w=246&m=10&text=http://longzhiye.top/2024/02/10/2024-02-10/">
              
            </li>
          </ul>
        
        
          <button class="mdui-btn mdui-btn-icon mdui-text-color-white" mdui-menu="{target: '#share_menu', align: 'right'}"><i class="mdui-icon material-icons">share</i></button>
          <ul class="mdui-menu" id="share_menu">
            <li class="mdui-menu-item">
              <a href="https://service.weibo.com/share/share.php?appkey=&title=Android 14 截屏流程解析&url=http://longzhiye.top/2024/02/10/2024-02-10/&pic=http://longzhiye.top/images/favicon.png&searchPic=false&style=simple" target="_blank" class="mdui-ripple">分享到 Weibo</a>
            </li>
            <li class="mdui-menu-item">
              <a href="https://twitter.com/intent/tweet?text=Android 14 截屏流程解析&url=http://longzhiye.top/2024/02/10/2024-02-10/&via=龙之叶" target="_blank" class="mdui-ripple">分享到 Twitter</a>
            </li>
            <li class="mdui-menu-item">
              <a href="https://www.facebook.com/sharer/sharer.php?u=http://longzhiye.top/2024/02/10/2024-02-10/" target="_blank" class="mdui-ripple">分享到 Facebook</a>
            </li>
            <li class="mdui-menu-item">
              <a href="https://plus.google.com/share?url=http://longzhiye.top/2024/02/10/2024-02-10/" target="_blank" class="mdui-ripple">分享到 Google+</a>
            </li>
            <li class="mdui-menu-item">
              <a href="https://www.linkedin.com/shareArticle?mini=true&url=http://longzhiye.top/2024/02/10/2024-02-10/&title=Android 14 截屏流程解析" target="_blank" class="mdui-ripple">分享到 LinkedIn</a>
            </li>
            <li class="mdui-menu-item">
              <a href="https://connect.qq.com/widget/shareqq/index.html?site=龙之叶的博客&title=Android 14 截屏流程解析&pics=http://longzhiye.top/images/favicon.png&url=http://longzhiye.top/2024/02/10/2024-02-10/" target="_blank" class="mdui-ripple">分享到 QQ</a>
            </li>
            <li class="mdui-menu-item">
              <a href="https://telegram.me/share/url?url=http://longzhiye.top/2024/02/10/2024-02-10/&text=Android 14 截屏流程解析" target="_blank" class="mdui-ripple">分享到 Telegram</a>
            </li>
          </ul>
        
      </div>
    </header>
    <div class="mdui-card-content mdui-typo">
      <h3 id="前言"><a href="#前言" class="headerlink" title="前言"></a>前言</h3><p>一般截屏都是电源键+音量减键，而这些按键的处理都是在 <strong>PhoneWindowManager</strong> 中进行的，但在该类中有两个主要处理按键的方法:</p>
<ul>
<li>interceptKeyBeforeQueueing()：主要处理音量键、电源键（Power键）、耳机键等。</li>
<li>interceptKeyBeforeDispatching()：处理一般性的按键和动作。</li>
</ul>
<p>参数含义：</p>
<ul>
<li>interactive：是否亮屏</li>
<li>KeyEvent.FLAG_FALLBACK：不被应用处理的按键事件或一些在  键值映射中不被处理的事件(例：轨迹球事件等)。</li>
</ul>
<p>这里我们直接看 <strong>PhoneWindowManager#interceptKeyBeforeQueueing()</strong> 方法：<br><strong>frameworks/base/services/core/java/com/android/server/policy/PhoneWindowManager.java</strong></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Override</span></span><br><span class="line"><span class="keyword">public</span> <span class="type">int</span> <span class="title function_">interceptKeyBeforeQueueing</span><span class="params">(KeyEvent event, <span class="type">int</span> policyFlags)</span> &#123;</span><br><span class="line">    <span class="keyword">final</span> <span class="type">int</span> <span class="variable">keyCode</span> <span class="operator">=</span> event.getKeyCode();</span><br><span class="line">    <span class="keyword">final</span> <span class="type">boolean</span> <span class="variable">down</span> <span class="operator">=</span> event.getAction() == KeyEvent.ACTION_DOWN;</span><br><span class="line">    <span class="type">boolean</span> <span class="variable">isWakeKey</span> <span class="operator">=</span> (policyFlags &amp; WindowManagerPolicy.FLAG_WAKE) != <span class="number">0</span></span><br><span class="line">            || event.isWakeKey();</span><br><span class="line">    <span class="keyword">if</span> (!mSystemBooted) &#123;</span><br><span class="line">        <span class="comment">// 省略部分代码......</span></span><br><span class="line">        <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="comment">// 省略部分代码......</span></span><br><span class="line">    <span class="comment">// This could prevent some wrong state in multi-displays environment,</span></span><br><span class="line">    <span class="comment">// the default display may turned off but interactive is true.</span></span><br><span class="line">    <span class="keyword">final</span> <span class="type">boolean</span> <span class="variable">isDefaultDisplayOn</span> <span class="operator">=</span> Display.isOnState(mDefaultDisplay.getState());</span><br><span class="line">    <span class="keyword">final</span> <span class="type">boolean</span> <span class="variable">interactiveAndOn</span> <span class="operator">=</span> interactive &amp;&amp; isDefaultDisplayOn;</span><br><span class="line">    <span class="keyword">if</span> ((event.getFlags() &amp; KeyEvent.FLAG_FALLBACK) == <span class="number">0</span>) &#123;</span><br><span class="line">        <span class="comment">// 这里面有·组合键处理，Android 14 与之前版本不一样</span></span><br><span class="line">        <span class="comment">// 在Android 14 有专门的组合键处理，可自行添加规则（即：组合键）</span></span><br><span class="line">        handleKeyGesture(event, interactiveAndOn);</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="comment">// 省略部分代码......</span></span><br><span class="line">    <span class="keyword">switch</span> (keyCode) &#123;</span><br><span class="line">        <span class="comment">// 省略部分代码......</span></span><br><span class="line">    <span class="keyword">return</span> result;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>上述代码里说的组合键添加，在 <strong>initKeyCombinationRules()</strong> 方法中，并在PhoneWindowManager的 <strong>init()</strong> 方法中初始化。关于 <strong>initKeyCombinationRules()</strong> 方法，下文会有讲述。<br>下面接着看 <strong>PhoneWindowManager#handleKeyGesture()</strong> 方法：<br><strong>frameworks/base/services/core/java/com/android/server/policy/PhoneWindowManager.java</strong></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">private</span> <span class="keyword">void</span> <span class="title function_">handleKeyGesture</span><span class="params">(KeyEvent event, <span class="type">boolean</span> interactive)</span> &#123;</span><br><span class="line">    <span class="comment">// 在 if 判断中，调用组合键判断；</span></span><br><span class="line">    <span class="comment">// 在将键事件发送到窗口之前，检查键事件是否可以被组合键规则拦截。</span></span><br><span class="line">    <span class="comment">// 如果键事件可以触发任何活动规则，则返回 true，否则返回 false。</span></span><br><span class="line">    <span class="keyword">if</span> (mKeyCombinationManager.interceptKey(event, interactive)) &#123;</span><br><span class="line">        <span class="comment">// handled by combo keys manager.</span></span><br><span class="line">        mSingleKeyGestureDetector.reset();</span><br><span class="line">        <span class="keyword">return</span>;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">if</span> (event.getKeyCode() == KEYCODE_POWER &amp;&amp; event.getAction() == KeyEvent.ACTION_DOWN) &#123;</span><br><span class="line">        <span class="comment">// 触发KEYCODE_POWER 和 ACTION_DOWN事件</span></span><br><span class="line">        mPowerKeyHandled = handleCameraGesture(event, interactive);</span><br><span class="line">        <span class="keyword">if</span> (mPowerKeyHandled) &#123;</span><br><span class="line">            <span class="comment">// handled by camera gesture.</span></span><br><span class="line">            mSingleKeyGestureDetector.reset();</span><br><span class="line">            <span class="keyword">return</span>;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    mSingleKeyGestureDetector.interceptKey(event, interactive);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>这里我们主要看 <strong>mKeyCombinationManager.interceptKey(event, interactive)</strong> 方法就行了；<br><strong>KeyCombinationManager#interceptKey():</strong><br><strong>frameworks/base/services/core/java/com/android/server/policy/KeyCombinationManager.java</strong></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">boolean</span> <span class="title function_">interceptKey</span><span class="params">(KeyEvent event, <span class="type">boolean</span> interactive)</span> &#123;</span><br><span class="line">    <span class="keyword">synchronized</span> (mLock) &#123;</span><br><span class="line">        <span class="keyword">return</span> interceptKeyLocked(event, interactive);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">private</span> <span class="type">boolean</span> <span class="title function_">interceptKeyLocked</span><span class="params">(KeyEvent event, <span class="type">boolean</span> interactive)</span> &#123;</span><br><span class="line">    <span class="keyword">final</span> <span class="type">boolean</span> <span class="variable">down</span> <span class="operator">=</span> event.getAction() == KeyEvent.ACTION_DOWN;</span><br><span class="line">    <span class="keyword">final</span> <span class="type">int</span> <span class="variable">keyCode</span> <span class="operator">=</span> event.getKeyCode();</span><br><span class="line">    <span class="keyword">final</span> <span class="type">int</span> <span class="variable">count</span> <span class="operator">=</span> mActiveRules.size();</span><br><span class="line">    <span class="keyword">final</span> <span class="type">long</span> <span class="variable">eventTime</span> <span class="operator">=</span> event.getEventTime();</span><br><span class="line">    <span class="keyword">if</span> (interactive &amp;&amp; down) &#123;</span><br><span class="line">        <span class="comment">// 省略部分代码......</span></span><br><span class="line">        <span class="keyword">if</span> (mDownTimes.size() == <span class="number">1</span>) &#123;</span><br><span class="line">                <span class="comment">// 省略部分代码......</span></span><br><span class="line">        &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">            <span class="comment">// 如果规则已经触发则忽略.</span></span><br><span class="line">            <span class="keyword">if</span> (mTriggeredRule != <span class="literal">null</span>) &#123;</span><br><span class="line">                <span class="keyword">return</span> <span class="literal">true</span>;</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="comment">// 发送给客户端之前的过度延迟。</span></span><br><span class="line">            forAllActiveRules((rule) -&gt; &#123;</span><br><span class="line">                <span class="keyword">if</span> (!rule.shouldInterceptKeys(mDownTimes)) &#123;</span><br><span class="line">                    <span class="keyword">return</span> <span class="literal">false</span>;</span><br><span class="line">                &#125;</span><br><span class="line">                Log.v(TAG, <span class="string">&quot;Performing combination rule : &quot;</span> + rule);</span><br><span class="line">                <span class="comment">// 主要是这个方法，会执行 execute() 方法，</span></span><br><span class="line">                <span class="comment">// 该方法是一个 抽象方法，会在添加组合键规则的地方实现；</span></span><br><span class="line">                mHandler.post(rule::execute);</span><br><span class="line">                mTriggeredRule = rule;</span><br><span class="line">                <span class="keyword">return</span> <span class="literal">true</span>;</span><br><span class="line">            &#125;);</span><br><span class="line">            mActiveRules.clear();</span><br><span class="line">            <span class="keyword">if</span> (mTriggeredRule != <span class="literal">null</span>) &#123;</span><br><span class="line">                mActiveRules.add(mTriggeredRule);</span><br><span class="line">                <span class="keyword">return</span> <span class="literal">true</span>;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">            <span class="comment">// 省略部分代码......</span></span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">return</span> <span class="literal">false</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>这里我们看下组合键添加，及触发回调。<br><strong>initKeyCombinationRules()</strong><br><strong>frameworks/base/services/core/java/com/android/server/policy/PhoneWindowManager.java</strong></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">private</span> <span class="keyword">void</span> <span class="title function_">initKeyCombinationRules</span><span class="params">()</span> &#123;</span><br><span class="line">    mKeyCombinationManager = <span class="keyword">new</span> <span class="title class_">KeyCombinationManager</span>(mHandler);</span><br><span class="line">    <span class="keyword">final</span> <span class="type">boolean</span> <span class="variable">screenshotChordEnabled</span> <span class="operator">=</span> mContext.getResources().getBoolean(</span><br><span class="line">            com.android.internal.R.bool.config_enableScreenshotChord);</span><br><span class="line">    <span class="keyword">if</span> (screenshotChordEnabled) &#123;</span><br><span class="line">        mKeyCombinationManager.addRule(</span><br><span class="line">                <span class="comment">// 截屏组合键的添加</span></span><br><span class="line">                <span class="keyword">new</span> <span class="title class_">TwoKeysCombinationRule</span>(KEYCODE_VOLUME_DOWN, KEYCODE_POWER) &#123;</span><br><span class="line">                    <span class="comment">// 触发组合键后回调</span></span><br><span class="line">                    <span class="meta">@Override</span></span><br><span class="line">                    <span class="keyword">void</span> <span class="title function_">execute</span><span class="params">()</span> &#123;</span><br><span class="line">                        mPowerKeyHandled = <span class="literal">true</span>;</span><br><span class="line">                        <span class="comment">// 发消息准备屏幕截图</span></span><br><span class="line">                        interceptScreenshotChord(TAKE_SCREENSHOT_FULLSCREEN,</span><br><span class="line">                                SCREENSHOT_KEY_CHORD, getScreenshotChordLongPressDelay());</span><br><span class="line">                    &#125;</span><br><span class="line">                    <span class="comment">// 取消</span></span><br><span class="line">                    <span class="meta">@Override</span></span><br><span class="line">                    <span class="keyword">void</span> <span class="title function_">cancel</span><span class="params">()</span> &#123;</span><br><span class="line">                        cancelPendingScreenshotChordAction();</span><br><span class="line">                    &#125;</span><br><span class="line">                &#125;);</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="comment">// 省略部分代码......</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>上面通过 handle 发了一个消息，将会调用 <strong>handleScreenShot()</strong> 方法，处理截屏：<br><strong>PhoneWindowManager# handleScreenShot()</strong><br><strong>frameworks/base/services/core/java/com/android/server/policy/PhoneWindowManager.java</strong></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">private</span> <span class="keyword">void</span> <span class="title function_">handleScreenShot</span><span class="params">(<span class="meta">@WindowManager</span>.ScreenshotType <span class="type">int</span> type,</span></span><br><span class="line"><span class="params">        <span class="meta">@WindowManager</span>.ScreenshotSource <span class="type">int</span> source)</span> &#123;</span><br><span class="line">    <span class="comment">// 回调到 DisplayPolicy.java</span></span><br><span class="line">    mDefaultDisplayPolicy.takeScreenshot(type, source);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p><strong>DisplayPolicy#takeScreenshot()</strong><br><strong>frameworks/base/services/core/java/com/android/server/wm/DisplayPolicy.java</strong></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 请求截取屏幕截图</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">takeScreenshot</span><span class="params">(<span class="type">int</span> screenshotType, <span class="type">int</span> source)</span> &#123;</span><br><span class="line">    <span class="keyword">if</span> (mScreenshotHelper != <span class="literal">null</span>) &#123;</span><br><span class="line">        mScreenshotHelper.takeScreenshot(screenshotType,</span><br><span class="line">                getStatusBar() != <span class="literal">null</span> &amp;&amp; getStatusBar().isVisible(),</span><br><span class="line">                getNavigationBar() != <span class="literal">null</span> &amp;&amp; getNavigationBar().isVisible(),</span><br><span class="line">                source, mHandler, <span class="literal">null</span> <span class="comment">/* completionConsumer */</span>);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>继续往下看 <strong>ScreenshotHelper#takeScreenshot()</strong><br><strong>frameworks/base/core/java/com/android/internal/util/ScreenshotHelper.java</strong></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">takeScreenshot</span><span class="params">(<span class="keyword">final</span> <span class="type">int</span> screenshotType, <span class="keyword">final</span> <span class="type">boolean</span> hasStatus,</span></span><br><span class="line"><span class="params">        <span class="keyword">final</span> <span class="type">boolean</span> hasNav, <span class="type">int</span> source, <span class="meta">@NonNull</span> Handler handler,</span></span><br><span class="line"><span class="params">        <span class="meta">@Nullable</span> Consumer&lt;Uri&gt; completionConsumer)</span> &#123;</span><br><span class="line">    <span class="comment">// 截图请求</span></span><br><span class="line">    <span class="type">ScreenshotRequest</span> <span class="variable">screenshotRequest</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">ScreenshotRequest</span>(source, hasStatus, hasNav);</span><br><span class="line">    takeScreenshot(screenshotType, SCREENSHOT_TIMEOUT_MS, handler, screenshotRequest,</span><br><span class="line">            completionConsumer);</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">//到了 Binder调用环节, 此为客户端, 服务端为SystemUI中的 TakeScreenshotService</span></span><br><span class="line"><span class="keyword">private</span> <span class="keyword">void</span> <span class="title function_">takeScreenshot</span><span class="params">(<span class="keyword">final</span> <span class="type">int</span> screenshotType, <span class="type">long</span> timeoutMs, <span class="meta">@NonNull</span> Handler handler,</span></span><br><span class="line"><span class="params">            ScreenshotRequest screenshotRequest, <span class="meta">@Nullable</span> Consumer&lt;Uri&gt; completionConsumer)</span> &#123;</span><br><span class="line">        <span class="keyword">synchronized</span> (mScreenshotLock) &#123;</span><br><span class="line">            <span class="keyword">final</span> <span class="type">Runnable</span> <span class="variable">mScreenshotTimeout</span> <span class="operator">=</span> () -&gt; &#123;</span><br><span class="line">                <span class="keyword">synchronized</span> (mScreenshotLock) &#123;</span><br><span class="line">                    <span class="keyword">if</span> (mScreenshotConnection != <span class="literal">null</span>) &#123;</span><br><span class="line">                        <span class="comment">// 在获取屏幕截图捕获响应之前超时</span></span><br><span class="line">                        Log.e(TAG, <span class="string">&quot;Timed out before getting screenshot capture response&quot;</span>);</span><br><span class="line">                        <span class="comment">// 重置连接</span></span><br><span class="line">                        resetConnection();</span><br><span class="line">                        <span class="comment">// 通知截屏错误</span></span><br><span class="line">                        notifyScreenshotError();</span><br><span class="line">                    &#125;</span><br><span class="line">                &#125;</span><br><span class="line">                <span class="keyword">if</span> (completionConsumer != <span class="literal">null</span>) &#123;</span><br><span class="line">                    completionConsumer.accept(<span class="literal">null</span>);</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;;</span><br><span class="line">            <span class="type">Message</span> <span class="variable">msg</span> <span class="operator">=</span> Message.obtain(<span class="literal">null</span>, screenshotType, screenshotRequest);</span><br><span class="line">            <span class="type">Handler</span> <span class="variable">h</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">Handler</span>(handler.getLooper()) &#123;</span><br><span class="line">                <span class="meta">@Override</span></span><br><span class="line">                <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">handleMessage</span><span class="params">(Message msg)</span> &#123;</span><br><span class="line">                    <span class="keyword">switch</span> (msg.what) &#123;</span><br><span class="line">                        <span class="keyword">case</span> SCREENSHOT_MSG_URI:</span><br><span class="line">                            <span class="keyword">if</span> (completionConsumer != <span class="literal">null</span>) &#123;</span><br><span class="line">                                completionConsumer.accept((Uri) msg.obj);</span><br><span class="line">                            &#125;</span><br><span class="line">                            handler.removeCallbacks(mScreenshotTimeout);</span><br><span class="line">                            <span class="keyword">break</span>;</span><br><span class="line">                        <span class="keyword">case</span> SCREENSHOT_MSG_PROCESS_COMPLETE:</span><br><span class="line">                            <span class="keyword">synchronized</span> (mScreenshotLock) &#123;</span><br><span class="line">                                resetConnection();</span><br><span class="line">                            &#125;</span><br><span class="line">                            <span class="keyword">break</span>;</span><br><span class="line">                    &#125;</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;;</span><br><span class="line">            msg.replyTo = <span class="keyword">new</span> <span class="title class_">Messenger</span>(h);</span><br><span class="line">            <span class="keyword">if</span> (mScreenshotConnection == <span class="literal">null</span> || mScreenshotService == <span class="literal">null</span>) &#123;</span><br><span class="line">                <span class="comment">// 一个标准的Service连接</span></span><br><span class="line">                <span class="comment">// config_screenshotServiceComponent == com.android.systemui/com.android.systemui.screenshot.TakeScreenshotService</span></span><br><span class="line">                <span class="keyword">final</span> <span class="type">ComponentName</span> <span class="variable">serviceComponent</span> <span class="operator">=</span> ComponentName.unflattenFromString(</span><br><span class="line">                        mContext.getResources().getString(</span><br><span class="line">                                com.android.internal.R.string.config_screenshotServiceComponent));</span><br><span class="line">                <span class="keyword">final</span> <span class="type">Intent</span> <span class="variable">serviceIntent</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">Intent</span>();</span><br><span class="line">                serviceIntent.setComponent(serviceComponent);</span><br><span class="line">                <span class="type">ServiceConnection</span> <span class="variable">conn</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">ServiceConnection</span>() &#123;</span><br><span class="line">                    <span class="meta">@Override</span></span><br><span class="line">                    <span class="comment">// 当Service连接成功之后</span></span><br><span class="line">                    <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">onServiceConnected</span><span class="params">(ComponentName name, IBinder service)</span> &#123;</span><br><span class="line">                        <span class="keyword">synchronized</span> (mScreenshotLock) &#123;</span><br><span class="line">                            <span class="keyword">if</span> (mScreenshotConnection != <span class="built_in">this</span>) &#123;</span><br><span class="line">                                <span class="keyword">return</span>;</span><br><span class="line">                            &#125;</span><br><span class="line">                            mScreenshotService = service;</span><br><span class="line">                            <span class="type">Messenger</span> <span class="variable">messenger</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">Messenger</span>(mScreenshotService);</span><br><span class="line">                            <span class="keyword">try</span> &#123;</span><br><span class="line">                                <span class="comment">// 进程通信，发送请求截图消息</span></span><br><span class="line">                                messenger.send(msg);</span><br><span class="line">                            &#125; <span class="keyword">catch</span> (RemoteException e) &#123;</span><br><span class="line">                                Log.e(TAG, <span class="string">&quot;Couldn&#x27;t take screenshot: &quot;</span> + e);</span><br><span class="line">                                <span class="keyword">if</span> (completionConsumer != <span class="literal">null</span>) &#123;</span><br><span class="line">                                    completionConsumer.accept(<span class="literal">null</span>);</span><br><span class="line">                                &#125;</span><br><span class="line">                            &#125;</span><br><span class="line">                        &#125;</span><br><span class="line">                    &#125;</span><br><span class="line">                    <span class="meta">@Override</span></span><br><span class="line">                    <span class="comment">// 当Service断开连接时</span></span><br><span class="line">                    <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">onServiceDisconnected</span><span class="params">(ComponentName name)</span> &#123;</span><br><span class="line">                        <span class="keyword">synchronized</span> (mScreenshotLock) &#123;</span><br><span class="line">                            <span class="keyword">if</span> (mScreenshotConnection != <span class="literal">null</span>) &#123;</span><br><span class="line">                                resetConnection();</span><br><span class="line">                                <span class="comment">// only log an error if we&#x27;re still within the timeout period</span></span><br><span class="line">                                <span class="keyword">if</span> (handler.hasCallbacks(mScreenshotTimeout)) &#123;</span><br><span class="line">                                    handler.removeCallbacks(mScreenshotTimeout);</span><br><span class="line">                                    notifyScreenshotError();</span><br><span class="line">                                &#125;</span><br><span class="line">                            &#125;</span><br><span class="line">                        &#125;</span><br><span class="line">                    &#125;</span><br><span class="line">                &#125;;</span><br><span class="line">                <span class="comment">// 绑定服务 TakeScreenshotService；</span></span><br><span class="line">                <span class="comment">// 绑定成功为true，不成功则发绑定超时消息</span></span><br><span class="line">                <span class="keyword">if</span> (mContext.bindServiceAsUser(serviceIntent, conn,</span><br><span class="line">                        Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE,</span><br><span class="line">                        UserHandle.CURRENT)) &#123;</span><br><span class="line">                    mScreenshotConnection = conn;</span><br><span class="line">                    handler.postDelayed(mScreenshotTimeout, timeoutMs);</span><br><span class="line">                &#125;</span><br><span class="line">            &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">                <span class="comment">// 如果已经连接则直接发送Message</span></span><br><span class="line">                <span class="type">Messenger</span> <span class="variable">messenger</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">Messenger</span>(mScreenshotService);</span><br><span class="line">                <span class="keyword">try</span> &#123;</span><br><span class="line">                    messenger.send(msg);</span><br><span class="line">                &#125; <span class="keyword">catch</span> (RemoteException e) &#123;</span><br><span class="line">                    Log.e(TAG, <span class="string">&quot;Couldn&#x27;t take screenshot: &quot;</span> + e);</span><br><span class="line">                    <span class="keyword">if</span> (completionConsumer != <span class="literal">null</span>) &#123;</span><br><span class="line">                        completionConsumer.accept(<span class="literal">null</span>);</span><br><span class="line">                    &#125;</span><br><span class="line">                &#125;</span><br><span class="line">                handler.postDelayed(mScreenshotTimeout, timeoutMs);</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>客户端通过向服务端发送 message 来将截屏任务交给 service，由 service 处理后面的操作。<br><strong>frameworks/base/packages/SystemUI/src/com/android/systemui/screenshot/TakeScreenshotService.java</strong></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 通过 Binder (Messenger) 响应传入消息</span></span><br><span class="line"><span class="meta">@MainThread</span></span><br><span class="line"><span class="keyword">private</span> <span class="type">boolean</span> <span class="title function_">handleMessage</span><span class="params">(Message msg)</span> &#123;</span><br><span class="line">    <span class="comment">// 获取客户端传的 Messenger 对象</span></span><br><span class="line">    <span class="keyword">final</span> <span class="type">Messenger</span> <span class="variable">replyTo</span> <span class="operator">=</span> msg.replyTo;</span><br><span class="line">    <span class="comment">// reportUri(replyTo, uri)  方法，Messenger 双向通信，</span></span><br><span class="line">    <span class="comment">// 在服务端用远程客户端的 Messenger 对象给客户端发送信息</span></span><br><span class="line">    <span class="keyword">final</span> Consumer&lt;Uri&gt; uriConsumer = (uri) -&gt; reportUri(replyTo, uri);</span><br><span class="line">    <span class="type">RequestCallback</span> <span class="variable">requestCallback</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">RequestCallbackImpl</span>(replyTo);</span><br><span class="line">    <span class="comment">// 如果此用户的存储空间被锁定，我们就没有地方可以存储屏幕截图，</span></span><br><span class="line">    <span class="comment">// 因此请跳过截屏，而不是显示误导性的动画和错误通知。</span></span><br><span class="line">    <span class="keyword">if</span> (!mUserManager.isUserUnlocked()) &#123;</span><br><span class="line">        mNotificationsController.notifyScreenshotError(</span><br><span class="line">                R.string.screenshot_failed_to_save_user_locked_text);</span><br><span class="line">        requestCallback.reportError();</span><br><span class="line">        <span class="keyword">return</span> <span class="literal">true</span>;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">if</span> (mDevicePolicyManager.getScreenCaptureDisabled(<span class="literal">null</span>, UserHandle.USER_ALL)) &#123;</span><br><span class="line">        mBgExecutor.execute(() -&gt; &#123;</span><br><span class="line">            <span class="comment">// 跳过屏幕截图，因为 IT 管理员已禁用设备上的“+”屏幕截图</span></span><br><span class="line">            <span class="type">String</span> <span class="variable">blockedByAdminText</span> <span class="operator">=</span> mDevicePolicyManager.getResources().getString(</span><br><span class="line">                    SCREENSHOT_BLOCKED_BY_ADMIN,</span><br><span class="line">                    () -&gt; mContext.getString(R.string.screenshot_blocked_by_admin));</span><br><span class="line">            mHandler.post(() -&gt;</span><br><span class="line">                    Toast.makeText(mContext, blockedByAdminText, Toast.LENGTH_SHORT).show());</span><br><span class="line">            requestCallback.reportError();</span><br><span class="line">        &#125;);</span><br><span class="line">        <span class="keyword">return</span> <span class="literal">true</span>;</span><br><span class="line">    &#125;</span><br><span class="line">    ScreenshotHelper.<span class="type">ScreenshotRequest</span> <span class="variable">screenshotRequest</span> <span class="operator">=</span></span><br><span class="line">            (ScreenshotHelper.ScreenshotRequest) msg.obj;</span><br><span class="line">    <span class="type">ComponentName</span> <span class="variable">topComponent</span> <span class="operator">=</span> screenshotRequest.getTopComponent();</span><br><span class="line">    mUiEventLogger.log(ScreenshotEvent.getScreenshotSource(screenshotRequest.getSource()), <span class="number">0</span>,</span><br><span class="line">            topComponent == <span class="literal">null</span> ? <span class="string">&quot;&quot;</span> : topComponent.getPackageName());</span><br><span class="line">    <span class="keyword">switch</span> (msg.what) &#123;</span><br><span class="line">        <span class="keyword">case</span> WindowManager.TAKE_SCREENSHOT_FULLSCREEN:</span><br><span class="line">            <span class="comment">// 全屏截图</span></span><br><span class="line">            mScreenshot.takeScreenshotFullscreen(topComponent, uriConsumer, requestCallback);</span><br><span class="line">            <span class="keyword">break</span>;</span><br><span class="line">        <span class="keyword">case</span> WindowManager.TAKE_SCREENSHOT_SELECTED_REGION:</span><br><span class="line">            <span class="comment">// 截取所选区域</span></span><br><span class="line">            mScreenshot.takeScreenshotPartial(topComponent, uriConsumer, requestCallback);</span><br><span class="line">            <span class="keyword">break</span>;</span><br><span class="line">        <span class="keyword">case</span> WindowManager.TAKE_SCREENSHOT_PROVIDED_IMAGE:</span><br><span class="line">            <span class="comment">// 截取提供的图像</span></span><br><span class="line">            <span class="type">Bitmap</span> <span class="variable">screenshot</span> <span class="operator">=</span> ScreenshotHelper.HardwareBitmapBundler.bundleToHardwareBitmap(</span><br><span class="line">                    screenshotRequest.getBitmapBundle());</span><br><span class="line">            <span class="type">Rect</span> <span class="variable">screenBounds</span> <span class="operator">=</span> screenshotRequest.getBoundsInScreen();</span><br><span class="line">            <span class="type">Insets</span> <span class="variable">insets</span> <span class="operator">=</span> screenshotRequest.getInsets();</span><br><span class="line">            <span class="type">int</span> <span class="variable">taskId</span> <span class="operator">=</span> screenshotRequest.getTaskId();</span><br><span class="line">            <span class="type">int</span> <span class="variable">userId</span> <span class="operator">=</span> screenshotRequest.getUserId();</span><br><span class="line">            <span class="keyword">if</span> (screenshot == <span class="literal">null</span>) &#123;</span><br><span class="line">                <span class="comment">// 从屏幕截图消息中获得空位图</span></span><br><span class="line">                mNotificationsController.notifyScreenshotError(</span><br><span class="line">                        R.string.screenshot_failed_to_capture_text);</span><br><span class="line">                requestCallback.reportError();</span><br><span class="line">            &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">                mScreenshot.handleImageAsScreenshot(screenshot, screenBounds, insets,</span><br><span class="line">                        taskId, userId, topComponent, uriConsumer, requestCallback);</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="keyword">break</span>;</span><br><span class="line">        <span class="keyword">default</span>:</span><br><span class="line">            <span class="comment">// 无效的屏幕截图选项</span></span><br><span class="line">            Log.w(TAG, <span class="string">&quot;Invalid screenshot option: &quot;</span> + msg.what);</span><br><span class="line">            <span class="keyword">return</span> <span class="literal">false</span>;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">return</span> <span class="literal">true</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>TakeScreenshotService 调用 <strong>ScreenshotController.java</strong> 的 <strong>takeScreenshotFullscreen()</strong> ；<br><strong>ScreenshotController#takeScreenshotFullscreen()</strong><br><strong>frameworks/base/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotController.java</strong></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">void</span> <span class="title function_">takeScreenshotFullscreen</span><span class="params">(ComponentName topComponent, Consumer&lt;Uri&gt; finisher,</span></span><br><span class="line"><span class="params">        RequestCallback requestCallback)</span> &#123;</span><br><span class="line">    <span class="comment">// 断言，是主线程则继续执行，不是则抛出异常。</span></span><br><span class="line">    Assert.isMainThread();</span><br><span class="line">    mCurrentRequestCallback = requestCallback;</span><br><span class="line">    <span class="type">DisplayMetrics</span> <span class="variable">displayMetrics</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">DisplayMetrics</span>();</span><br><span class="line">    getDefaultDisplay().getRealMetrics(displayMetrics);</span><br><span class="line">    takeScreenshotInternal(</span><br><span class="line">            topComponent, finisher,</span><br><span class="line">            <span class="keyword">new</span> <span class="title class_">Rect</span>(<span class="number">0</span>, <span class="number">0</span>, displayMetrics.widthPixels, displayMetrics.heightPixels));</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">// 获取当前显示的屏幕截图并显示动画。</span></span><br><span class="line"><span class="keyword">private</span> <span class="keyword">void</span> <span class="title function_">takeScreenshotInternal</span><span class="params">(ComponentName topComponent, Consumer&lt;Uri&gt; finisher,</span></span><br><span class="line"><span class="params">        Rect crop)</span> &#123;</span><br><span class="line">    mScreenshotTakenInPortrait =</span><br><span class="line">            mContext.getResources().getConfiguration().orientation == ORIENTATION_PORTRAIT;</span><br><span class="line">    <span class="comment">// 复制输入 Rect，因为 SurfaceControl.screenshot 可以改变它</span></span><br><span class="line">    <span class="type">Rect</span> <span class="variable">screenRect</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">Rect</span>(crop);</span><br><span class="line">    <span class="comment">// 截图</span></span><br><span class="line">    <span class="type">Bitmap</span> <span class="variable">screenshot</span> <span class="operator">=</span> captureScreenshot(crop);</span><br><span class="line">    <span class="comment">// 屏幕截图位图为空</span></span><br><span class="line">    <span class="keyword">if</span> (screenshot == <span class="literal">null</span>) &#123;</span><br><span class="line">        mNotificationsController.notifyScreenshotError(</span><br><span class="line">                R.string.screenshot_failed_to_capture_text);</span><br><span class="line">        <span class="keyword">if</span> (mCurrentRequestCallback != <span class="literal">null</span>) &#123;</span><br><span class="line">            mCurrentRequestCallback.reportError();</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">return</span>;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="comment">// 保存截图</span></span><br><span class="line">    saveScreenshot(screenshot, finisher, screenRect, Insets.NONE, topComponent, <span class="literal">true</span>);</span><br><span class="line">    mBroadcastSender.sendBroadcast(<span class="keyword">new</span> <span class="title class_">Intent</span>(ClipboardOverlayController.SCREENSHOT_ACTION),</span><br><span class="line">            ClipboardOverlayController.SELF_PERMISSION);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>如何截图的呢？这里我们看 <strong>captureScreenshot()</strong> 方法;<br><strong>ScreenshotController#captureScreenshot()</strong><br><strong>frameworks/base/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotController.java</strong></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">private</span> Bitmap <span class="title function_">captureScreenshot</span><span class="params">(Rect crop)</span> &#123;</span><br><span class="line">    <span class="type">int</span> <span class="variable">width</span> <span class="operator">=</span> crop.width();</span><br><span class="line">    <span class="type">int</span> <span class="variable">height</span> <span class="operator">=</span> crop.height();</span><br><span class="line">    <span class="type">Bitmap</span> <span class="variable">screenshot</span> <span class="operator">=</span> <span class="literal">null</span>;</span><br><span class="line">    <span class="keyword">final</span> <span class="type">Display</span> <span class="variable">display</span> <span class="operator">=</span> getDefaultDisplay();</span><br><span class="line">    <span class="keyword">final</span> <span class="type">DisplayAddress</span> <span class="variable">address</span> <span class="operator">=</span> display.getAddress();</span><br><span class="line">    <span class="keyword">if</span> (!(address <span class="keyword">instanceof</span> DisplayAddress.Physical)) &#123;</span><br><span class="line">        Log.e(TAG, <span class="string">&quot;Skipping Screenshot - Default display does not have a physical address: &quot;</span></span><br><span class="line">                + display);</span><br><span class="line">    &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">        <span class="keyword">final</span> DisplayAddress.<span class="type">Physical</span> <span class="variable">physicalAddress</span> <span class="operator">=</span> (DisplayAddress.Physical) address;</span><br><span class="line">        <span class="keyword">final</span> <span class="type">IBinder</span> <span class="variable">displayToken</span> <span class="operator">=</span> SurfaceControl.getPhysicalDisplayToken(</span><br><span class="line">                physicalAddress.getPhysicalDisplayId());</span><br><span class="line">        <span class="comment">// 捕获参数</span></span><br><span class="line">        <span class="keyword">final</span> SurfaceControl.<span class="type">DisplayCaptureArgs</span> <span class="variable">captureArgs</span> <span class="operator">=</span></span><br><span class="line">                <span class="keyword">new</span> <span class="title class_">SurfaceControl</span>.DisplayCaptureArgs.Builder(displayToken)</span><br><span class="line">                        .setSourceCrop(crop)</span><br><span class="line">                        .setSize(width, height)</span><br><span class="line">                        .build();</span><br><span class="line">        <span class="comment">// 屏幕截图硬件缓存</span></span><br><span class="line">        <span class="keyword">final</span> SurfaceControl.<span class="type">ScreenshotHardwareBuffer</span> <span class="variable">screenshotBuffer</span> <span class="operator">=</span></span><br><span class="line">                SurfaceControl.captureDisplay(captureArgs);</span><br><span class="line">        <span class="comment">// 截图缓存</span></span><br><span class="line">        screenshot = screenshotBuffer == <span class="literal">null</span> ? <span class="literal">null</span> : screenshotBuffer.asBitmap();</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">return</span> screenshot;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>上面是捕获图片的过程，里面到底如何捕获的。这点我目前还没弄清。<br>接着拿到截屏的 Bitmap 后就可以进行图片保存，显示等等一些操作。<br>接着看 <strong>ScreenshotController#saveScreenshot()</strong><br><strong>frameworks/base/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotController.java</strong></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">private</span> <span class="keyword">void</span> <span class="title function_">saveScreenshot</span><span class="params">(Bitmap screenshot, Consumer&lt;Uri&gt; finisher, Rect screenRect,</span></span><br><span class="line"><span class="params">        Insets screenInsets, ComponentName topComponent, <span class="type">boolean</span> showFlash)</span> &#123;</span><br><span class="line">    withWindowAttached(() -&gt;</span><br><span class="line">            mScreenshotView.announceForAccessibility(</span><br><span class="line">                    mContext.getResources().getString(R.string.screenshot_saving_title)));</span><br><span class="line">    <span class="comment">// 判断缩略图的那个窗口是否已附加上去了。</span></span><br><span class="line">    <span class="comment">// ScreenshotView ：附件窗口的布局；有：略缩图，编辑按钮、长截屏按钮等一些其他布局。</span></span><br><span class="line">    <span class="keyword">if</span> (mScreenshotView.isAttachedToWindow()) &#123;</span><br><span class="line">        <span class="comment">// if we didn&#x27;t already dismiss for another reason</span></span><br><span class="line">        <span class="keyword">if</span> (!mScreenshotView.isDismissing()) &#123;</span><br><span class="line">            mUiEventLogger.log(ScreenshotEvent.SCREENSHOT_REENTERED, <span class="number">0</span>, mPackageName);</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">if</span> (DEBUG_WINDOW) &#123;</span><br><span class="line">            Log.d(TAG, <span class="string">&quot;saveScreenshot: screenshotView is already attached, resetting. &quot;</span></span><br><span class="line">                    + <span class="string">&quot;(dismissing=&quot;</span> + mScreenshotView.isDismissing() + <span class="string">&quot;)&quot;</span>);</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="comment">// 视图的状态重置，例如：可见性、透明度等。</span></span><br><span class="line">        mScreenshotView.reset();</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="comment">// 省略部分代码......</span></span><br><span class="line">    <span class="comment">// 在工作线程中保存屏幕截图。</span></span><br><span class="line">    saveScreenshotInWorkerThread(finisher, <span class="built_in">this</span>::showUiOnActionsReady,</span><br><span class="line">            <span class="built_in">this</span>::showUiOnQuickShareActionReady);</span><br><span class="line">    <span class="comment">// The window is focusable by default</span></span><br><span class="line">    setWindowFocusable(<span class="literal">true</span>);</span><br><span class="line">    <span class="comment">// Wait until this window is attached to request because it is</span></span><br><span class="line">    <span class="comment">// the reference used to locate the target window (below).</span></span><br><span class="line">    <span class="comment">// 这个方法没看明白。</span></span><br><span class="line">    withWindowAttached(() -&gt; &#123;</span><br><span class="line">        <span class="comment">// 请求滚动捕获，捕获长截屏的。</span></span><br><span class="line">        requestScrollCapture();</span><br><span class="line">        mWindow.peekDecorView().getViewRootImpl().setActivityConfigCallback(</span><br><span class="line">                <span class="keyword">new</span> <span class="title class_">ViewRootImpl</span>.ActivityConfigCallback() &#123;</span><br><span class="line">                    <span class="meta">@Override</span></span><br><span class="line">                    <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">onConfigurationChanged</span><span class="params">(Configuration overrideConfig,</span></span><br><span class="line"><span class="params">                            <span class="type">int</span> newDisplayId)</span> &#123;</span><br><span class="line">                                <span class="comment">// 省略部分代码......</span></span><br><span class="line">                    &#125;</span><br><span class="line">                    <span class="meta">@Override</span></span><br><span class="line">                    <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">requestCompatCameraControl</span><span class="params">(<span class="type">boolean</span> showControl,</span></span><br><span class="line"><span class="params">                            <span class="type">boolean</span> transformationApplied,</span></span><br><span class="line"><span class="params">                            ICompatCameraControlCallback callback)</span> &#123;</span><br><span class="line">                            <span class="comment">// 省略部分代码......</span></span><br><span class="line">                    &#125;</span><br><span class="line">                &#125;);</span><br><span class="line">    &#125;);</span><br><span class="line">    <span class="comment">// 创建附加窗口</span></span><br><span class="line">    attachWindow();</span><br><span class="line">    <span class="comment">// 省略部分代码......</span></span><br><span class="line">    </span><br><span class="line">    <span class="comment">// 设置缩略图，ScreenBitmap 为所截的图片</span></span><br><span class="line">    mScreenshotView.setScreenshot(mScreenBitmap, screenInsets);</span><br><span class="line">    <span class="comment">// 将 ScreenshotView 添加到附加窗口</span></span><br><span class="line">    setContentView(mScreenshotView);</span><br><span class="line">    <span class="comment">// 省略部分代码......</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>截屏布局 <strong>screenshot_static.xml</strong> ：<br><strong>frameworks/base/packages/SystemUI/res/layout/screenshot_static.xml</strong></p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">com.android.systemui.screenshot.DraggableConstraintLayout</span></span></span><br><span class="line"><span class="tag">    <span class="attr">xmlns:android</span>=<span class="string">&quot;http://schemas.android.com/apk/res/android&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">xmlns:app</span>=<span class="string">&quot;http://schemas.android.com/apk/res-auto&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:layout_width</span>=<span class="string">&quot;match_parent&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:layout_height</span>=<span class="string">&quot;match_parent&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">ImageView</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:id</span>=<span class="string">&quot;@+id/actions_container_background&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:visibility</span>=<span class="string">&quot;gone&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:layout_height</span>=<span class="string">&quot;0dp&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:layout_width</span>=<span class="string">&quot;0dp&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:elevation</span>=<span class="string">&quot;4dp&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:background</span>=<span class="string">&quot;@drawable/action_chip_container_background&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:layout_marginStart</span>=<span class="string">&quot;@dimen/overlay_action_container_margin_horizontal&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">app:layout_constraintBottom_toBottomOf</span>=<span class="string">&quot;@+id/actions_container&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">app:layout_constraintStart_toStartOf</span>=<span class="string">&quot;parent&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">app:layout_constraintTop_toTopOf</span>=<span class="string">&quot;@+id/actions_container&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">app:layout_constraintEnd_toEndOf</span>=<span class="string">&quot;@+id/actions_container&quot;</span>/&gt;</span></span><br><span class="line">    <span class="comment">&lt;!-- 缩略图下方的几个按钮 --&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">HorizontalScrollView</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:id</span>=<span class="string">&quot;@+id/actions_container&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:layout_width</span>=<span class="string">&quot;0dp&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:layout_height</span>=<span class="string">&quot;wrap_content&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:layout_marginEnd</span>=<span class="string">&quot;@dimen/overlay_action_container_margin_horizontal&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:layout_marginBottom</span>=<span class="string">&quot;4dp&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:paddingEnd</span>=<span class="string">&quot;@dimen/overlay_action_container_padding_right&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:paddingVertical</span>=<span class="string">&quot;@dimen/overlay_action_container_padding_vertical&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:elevation</span>=<span class="string">&quot;4dp&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:scrollbars</span>=<span class="string">&quot;none&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">app:layout_constraintHorizontal_bias</span>=<span class="string">&quot;0&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">app:layout_constraintWidth_percent</span>=<span class="string">&quot;1.0&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">app:layout_constraintWidth_max</span>=<span class="string">&quot;wrap&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">app:layout_constraintBottom_toBottomOf</span>=<span class="string">&quot;parent&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">app:layout_constraintStart_toEndOf</span>=<span class="string">&quot;@+id/screenshot_preview_border&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">app:layout_constraintEnd_toEndOf</span>=<span class="string">&quot;parent&quot;</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">LinearLayout</span></span></span><br><span class="line"><span class="tag">            <span class="attr">android:id</span>=<span class="string">&quot;@+id/screenshot_actions&quot;</span></span></span><br><span class="line"><span class="tag">            <span class="attr">android:layout_width</span>=<span class="string">&quot;wrap_content&quot;</span></span></span><br><span class="line"><span class="tag">            <span class="attr">android:layout_height</span>=<span class="string">&quot;wrap_content&quot;</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">include</span> <span class="attr">layout</span>=<span class="string">&quot;@layout/overlay_action_chip&quot;</span></span></span><br><span class="line"><span class="tag">                     <span class="attr">android:id</span>=<span class="string">&quot;@+id/screenshot_share_chip&quot;</span>/&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">include</span> <span class="attr">layout</span>=<span class="string">&quot;@layout/overlay_action_chip&quot;</span></span></span><br><span class="line"><span class="tag">                     <span class="attr">android:id</span>=<span class="string">&quot;@+id/screenshot_edit_chip&quot;</span>/&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">include</span> <span class="attr">layout</span>=<span class="string">&quot;@layout/overlay_action_chip&quot;</span></span></span><br><span class="line"><span class="tag">                     <span class="attr">android:id</span>=<span class="string">&quot;@+id/screenshot_scroll_chip&quot;</span></span></span><br><span class="line"><span class="tag">                     <span class="attr">android:visibility</span>=<span class="string">&quot;gone&quot;</span> /&gt;</span></span><br><span class="line">        <span class="tag">&lt;/<span class="name">LinearLayout</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">HorizontalScrollView</span>&gt;</span></span><br><span class="line">    <span class="comment">&lt;!-- 缩略图边框，使用 android:elevation=&quot;7dp&quot; 属性，确定哪个覆盖在哪个上面，值大的布局显示在上方 --&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">View</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:id</span>=<span class="string">&quot;@+id/screenshot_preview_border&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:layout_width</span>=<span class="string">&quot;0dp&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:layout_height</span>=<span class="string">&quot;0dp&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:layout_marginStart</span>=<span class="string">&quot;@dimen/overlay_offset_x&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:layout_marginBottom</span>=<span class="string">&quot;12dp&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:elevation</span>=<span class="string">&quot;7dp&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:alpha</span>=<span class="string">&quot;0&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:background</span>=<span class="string">&quot;@drawable/overlay_border&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">app:layout_constraintStart_toStartOf</span>=<span class="string">&quot;parent&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">app:layout_constraintBottom_toBottomOf</span>=<span class="string">&quot;parent&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">app:layout_constraintEnd_toEndOf</span>=<span class="string">&quot;@id/screenshot_preview_end&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">app:layout_constraintTop_toTopOf</span>=<span class="string">&quot;@id/screenshot_preview_top&quot;</span>/&gt;</span></span><br><span class="line">    <span class="comment">&lt;!-- constraintlayout 这种布局方式的，一个属性。 --&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">androidx.constraintlayout.widget.Barrier</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:id</span>=<span class="string">&quot;@+id/screenshot_preview_end&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:layout_width</span>=<span class="string">&quot;wrap_content&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:layout_height</span>=<span class="string">&quot;wrap_content&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">app:barrierMargin</span>=<span class="string">&quot;@dimen/overlay_border_width&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">app:barrierDirection</span>=<span class="string">&quot;end&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">app:constraint_referenced_ids</span>=<span class="string">&quot;screenshot_preview&quot;</span>/&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">androidx.constraintlayout.widget.Barrier</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:id</span>=<span class="string">&quot;@+id/screenshot_preview_top&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:layout_width</span>=<span class="string">&quot;wrap_content&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:layout_height</span>=<span class="string">&quot;wrap_content&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">app:barrierDirection</span>=<span class="string">&quot;top&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">app:barrierMargin</span>=<span class="string">&quot;@dimen/overlay_border_width_neg&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">app:constraint_referenced_ids</span>=<span class="string">&quot;screenshot_preview&quot;</span>/&gt;</span></span><br><span class="line">    <span class="comment">&lt;!-- 缩略图 --&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">ImageView</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:id</span>=<span class="string">&quot;@+id/screenshot_preview&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:visibility</span>=<span class="string">&quot;invisible&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:layout_width</span>=<span class="string">&quot;@dimen/overlay_x_scale&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:layout_margin</span>=<span class="string">&quot;@dimen/overlay_border_width&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:layout_height</span>=<span class="string">&quot;wrap_content&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:layout_gravity</span>=<span class="string">&quot;center&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:elevation</span>=<span class="string">&quot;7dp&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:contentDescription</span>=<span class="string">&quot;@string/screenshot_edit_description&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:scaleType</span>=<span class="string">&quot;fitEnd&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:background</span>=<span class="string">&quot;@drawable/overlay_preview_background&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:adjustViewBounds</span>=<span class="string">&quot;true&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:clickable</span>=<span class="string">&quot;true&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">app:layout_constraintBottom_toBottomOf</span>=<span class="string">&quot;@id/screenshot_preview_border&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">app:layout_constraintStart_toStartOf</span>=<span class="string">&quot;@id/screenshot_preview_border&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">app:layout_constraintEnd_toEndOf</span>=<span class="string">&quot;@id/screenshot_preview_border&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">app:layout_constraintTop_toTopOf</span>=<span class="string">&quot;@id/screenshot_preview_border&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">ImageView</span>&gt;</span></span><br><span class="line">    <span class="comment">&lt;!--add by jingtao.guo TFBAAA-2325 添加截图&quot;X&quot;图标--&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">FrameLayout</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:id</span>=<span class="string">&quot;@+id/screenshot_dismiss_button&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:layout_width</span>=<span class="string">&quot;@dimen/overlay_dismiss_button_tappable_size&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:layout_height</span>=<span class="string">&quot;@dimen/overlay_dismiss_button_tappable_size&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:elevation</span>=<span class="string">&quot;10dp&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">app:layout_constraintStart_toEndOf</span>=<span class="string">&quot;@id/screenshot_preview&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">app:layout_constraintEnd_toEndOf</span>=<span class="string">&quot;@id/screenshot_preview&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">app:layout_constraintTop_toTopOf</span>=<span class="string">&quot;@id/screenshot_preview&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">app:layout_constraintBottom_toTopOf</span>=<span class="string">&quot;@id/screenshot_preview&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:contentDescription</span>=<span class="string">&quot;@string/screenshot_dismiss_description&quot;</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">ImageView</span></span></span><br><span class="line"><span class="tag">            <span class="attr">android:id</span>=<span class="string">&quot;@+id/screenshot_dismiss_image&quot;</span></span></span><br><span class="line"><span class="tag">            <span class="attr">android:layout_width</span>=<span class="string">&quot;match_parent&quot;</span></span></span><br><span class="line"><span class="tag">            <span class="attr">android:layout_height</span>=<span class="string">&quot;match_parent&quot;</span></span></span><br><span class="line"><span class="tag">            <span class="attr">android:layout_margin</span>=<span class="string">&quot;@dimen/overlay_dismiss_button_margin&quot;</span></span></span><br><span class="line"><span class="tag">            <span class="attr">android:src</span>=<span class="string">&quot;@drawable/overlay_cancel&quot;</span>/&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">FrameLayout</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">ImageView</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:id</span>=<span class="string">&quot;@+id/screenshot_scrollable_preview&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:layout_width</span>=<span class="string">&quot;wrap_content&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:layout_height</span>=<span class="string">&quot;wrap_content&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:scaleType</span>=<span class="string">&quot;matrix&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:visibility</span>=<span class="string">&quot;gone&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">app:layout_constraintStart_toStartOf</span>=<span class="string">&quot;@id/screenshot_preview&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">app:layout_constraintTop_toTopOf</span>=<span class="string">&quot;@id/screenshot_preview&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:elevation</span>=<span class="string">&quot;7dp&quot;</span>/&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">com.android.systemui.screenshot.DraggableConstraintLayout</span>&gt;</span></span><br></pre></td></tr></table></figure>
<p>至此，全截屏流程就到此结束，<strong>saveScreenshotInWorkerThread()</strong> 这里不做分析。<br>下面分析长截屏：<br>在上述代码中，有讲到 <strong>requestScrollCapture()</strong> ，请求滚动捕获，即长截屏。<br><strong>ScreenshotController#requestScrollCapture()</strong><br><strong>frameworks/base/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotController.java</strong></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">private</span> <span class="keyword">void</span> <span class="title function_">requestScrollCapture</span><span class="params">()</span> &#123;</span><br><span class="line">    <span class="keyword">if</span> (!allowLongScreenshots()) &#123;</span><br><span class="line">        Log.d(TAG, <span class="string">&quot;Long screenshots not supported on this device&quot;</span>);</span><br><span class="line">        <span class="keyword">return</span>;</span><br><span class="line">    &#125;</span><br><span class="line">    mScrollCaptureClient.setHostWindowToken(mWindow.getDecorView().getWindowToken());</span><br><span class="line">    <span class="keyword">if</span> (mLastScrollCaptureRequest != <span class="literal">null</span>) &#123;</span><br><span class="line">        mLastScrollCaptureRequest.cancel(<span class="literal">true</span>);</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="comment">// 请求长截图捕获</span></span><br><span class="line">    <span class="keyword">final</span> ListenableFuture&lt;ScrollCaptureResponse&gt; future =</span><br><span class="line">            mScrollCaptureClient.request(DEFAULT_DISPLAY);</span><br><span class="line">    mLastScrollCaptureRequest = future;</span><br><span class="line">    mLastScrollCaptureRequest.addListener(() -&gt;</span><br><span class="line">            onScrollCaptureResponseReady(future), mMainExecutor);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<blockquote>
<p>长截图捕获流程： <strong>mScrollCaptureClient.request()</strong> 请求捕获 <strong>→mWindowManagerService.requestScrollCapture()→ViewRootImpl#requestScrollCapture()→ViewRootImpl#handleScrollCaptureRequest()</strong> 处理滚动捕获请求，拿到捕获目标。 <strong>→ViewGroup#dispatchScrollCaptureSearch()</strong> 通过检查此视图，处理滚动捕获搜索请求，然后检查每个子视图。该隐藏的隐藏，设置视图偏移等等。</p>
</blockquote>
<p>走完上述流程，才会继续往下执行；<br>接着看 <strong>ScreenshotController#onScrollCaptureResponseReady()</strong><br><strong>frameworks/base/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotController.java</strong></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">private</span> <span class="keyword">void</span> <span class="title function_">onScrollCaptureResponseReady</span><span class="params">(Future&lt;ScrollCaptureResponse&gt; responseFuture)</span> &#123;</span><br><span class="line">    <span class="keyword">try</span> &#123;</span><br><span class="line">        <span class="comment">// 上次滚动捕获响应</span></span><br><span class="line">        <span class="keyword">if</span> (mLastScrollCaptureResponse != <span class="literal">null</span>) &#123;</span><br><span class="line">            mLastScrollCaptureResponse.close();</span><br><span class="line">            mLastScrollCaptureResponse = <span class="literal">null</span>;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="comment">// 长截屏响应，这和 网络请求中，响应头类似， response 里有很多的数据。</span></span><br><span class="line">        <span class="keyword">if</span> (responseFuture != <span class="literal">null</span>) &#123;</span><br><span class="line">            <span class="keyword">if</span> (responseFuture.isCancelled()) &#123;</span><br><span class="line">                <span class="keyword">return</span>;</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="comment">// 将本次滚动捕获响应 设置成 滚动捕获响应</span></span><br><span class="line">            mLastScrollCaptureResponse = responseFuture.get();</span><br><span class="line">        &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">            Log.e(TAG, <span class="string">&quot;onScrollCaptureResponseReady responseFuture is null!&quot;</span>);</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">if</span> (mLastScrollCaptureResponse != <span class="literal">null</span> &amp;&amp; !mLastScrollCaptureResponse.isConnected()) &#123;</span><br><span class="line">            <span class="comment">// No connection means that the target window wasn&#x27;t found</span></span><br><span class="line">            <span class="comment">// or that it cannot support scroll capture.</span></span><br><span class="line">            Log.d(TAG, <span class="string">&quot;ScrollCapture: &quot;</span> + mLastScrollCaptureResponse.getDescription() + <span class="string">&quot; [&quot;</span></span><br><span class="line">                    + mLastScrollCaptureResponse.getWindowTitle() + <span class="string">&quot;]&quot;</span>);</span><br><span class="line">            <span class="keyword">return</span>;</span><br><span class="line">        &#125;</span><br><span class="line">        Log.d(TAG, <span class="string">&quot;ScrollCapture: connected to window [&quot;</span></span><br><span class="line">                + mLastScrollCaptureResponse.getWindowTitle() + <span class="string">&quot;]&quot;</span>);</span><br><span class="line">        <span class="comment">// 滚动捕获响应，这和 网络请求中，响应头类似， response 里有很多的数据。</span></span><br><span class="line">        <span class="keyword">final</span> <span class="type">ScrollCaptureResponse</span> <span class="variable">response</span> <span class="operator">=</span> mLastScrollCaptureResponse;</span><br><span class="line">        <span class="comment">// 截取更多内容按钮，即长截屏按钮；这里确实奇怪：还没点击长截屏，有些数据就已经捕获好了，例如：显示范围内的窗口边界、窗口空间中滚动内容的边界、当前窗口标题等等数据。</span></span><br><span class="line">        mScreenshotView.showScrollChip(response.getPackageName(), <span class="comment">/* onClick */</span> () -&gt; &#123;</span><br><span class="line">            <span class="type">DisplayMetrics</span> <span class="variable">displayMetrics</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">DisplayMetrics</span>();</span><br><span class="line">            getDefaultDisplay().getRealMetrics(displayMetrics);</span><br><span class="line">            <span class="comment">// 新的位图 Bitmap  。</span></span><br><span class="line">            <span class="type">Bitmap</span> <span class="variable">newScreenshot</span> <span class="operator">=</span> captureScreenshot(</span><br><span class="line">                    <span class="keyword">new</span> <span class="title class_">Rect</span>(<span class="number">0</span>, <span class="number">0</span>, displayMetrics.widthPixels, displayMetrics.heightPixels));</span><br><span class="line">            <span class="comment">// 设置视图，这里只是一个缩略图，和普通截图一样大；</span></span><br><span class="line">            mScreenshotView.prepareScrollingTransition(response, mScreenBitmap, newScreenshot,</span><br><span class="line">                    mScreenshotTakenInPortrait);</span><br><span class="line">            <span class="comment">// delay starting scroll capture to make sure the scrim is up before the app moves</span></span><br><span class="line">            <span class="comment">// 捕获视图。长截图会在 LongScreenshotActivity 显示。</span></span><br><span class="line">            mScreenshotView.post(() -&gt; runBatchScrollCapture(response));</span><br><span class="line">        &#125;);</span><br><span class="line">    &#125; <span class="keyword">catch</span> (InterruptedException | ExecutionException e) &#123;</span><br><span class="line">        Log.e(TAG, <span class="string">&quot;requestScrollCapture failed&quot;</span>, e);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">private</span> <span class="keyword">void</span> <span class="title function_">runBatchScrollCapture</span><span class="params">(ScrollCaptureResponse response)</span> &#123;</span><br><span class="line">    <span class="comment">// Clear the reference to prevent close() in dismissScreenshot</span></span><br><span class="line">    mLastScrollCaptureResponse = <span class="literal">null</span>;</span><br><span class="line">    <span class="keyword">if</span> (mLongScreenshotFuture != <span class="literal">null</span>) &#123;</span><br><span class="line">        mLongScreenshotFuture.cancel(<span class="literal">true</span>);</span><br><span class="line">    &#125; </span><br><span class="line">    <span class="comment">// 通过 response 得到 LongScreen 的视图。</span></span><br><span class="line">    mLongScreenshotFuture = mScrollCaptureController.run(response);</span><br><span class="line">    mLongScreenshotFuture.addListener(() -&gt; &#123;</span><br><span class="line">        ScrollCaptureController.LongScreenshot longScreenshot;</span><br><span class="line">        <span class="keyword">try</span> &#123;</span><br><span class="line">            <span class="comment">// 获取 longScreenshot 。</span></span><br><span class="line">            longScreenshot = mLongScreenshotFuture.get();</span><br><span class="line">        &#125; <span class="keyword">catch</span> (CancellationException e) &#123;</span><br><span class="line">            Log.e(TAG, <span class="string">&quot;Long screenshot cancelled&quot;</span>);</span><br><span class="line">            <span class="keyword">return</span>;</span><br><span class="line">        &#125; <span class="keyword">catch</span> (InterruptedException | ExecutionException e) &#123;</span><br><span class="line">            Log.e(TAG, <span class="string">&quot;Exception&quot;</span>, e);</span><br><span class="line">            mScreenshotView.restoreNonScrollingUi();</span><br><span class="line">            <span class="keyword">return</span>;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">if</span> (longScreenshot.getHeight() == <span class="number">0</span>) &#123;</span><br><span class="line">            mScreenshotView.restoreNonScrollingUi();</span><br><span class="line">            <span class="keyword">return</span>;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="comment">// 相当于数据保存，把截图数据设置进去，但这里不是存储在本地。</span></span><br><span class="line">        mLongScreenshotHolder.setLongScreenshot(longScreenshot);</span><br><span class="line">        mLongScreenshotHolder.setTransitionDestinationCallback(</span><br><span class="line">                (transitionDestination, onTransitionEnd) -&gt;</span><br><span class="line">                        mScreenshotView.startLongScreenshotTransition(</span><br><span class="line">                                transitionDestination, onTransitionEnd,</span><br><span class="line">                                longScreenshot));</span><br><span class="line">        <span class="keyword">final</span> <span class="type">Intent</span> <span class="variable">intent</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">Intent</span>(mContext, LongScreenshotActivity.class);</span><br><span class="line">        intent.setFlags(</span><br><span class="line">                Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);</span><br><span class="line">        <span class="comment">// 跳转到编辑界面，也可以叫预览界面吧。</span></span><br><span class="line">        mContext.startActivity(intent,</span><br><span class="line">                ActivityOptions.makeCustomAnimation(mContext, <span class="number">0</span>, <span class="number">0</span>).toBundle());</span><br><span class="line">        <span class="type">RemoteAnimationAdapter</span> <span class="variable">runner</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">RemoteAnimationAdapter</span>(</span><br><span class="line">                SCREENSHOT_REMOTE_RUNNER, <span class="number">0</span>, <span class="number">0</span>);</span><br><span class="line">        <span class="keyword">try</span> &#123;</span><br><span class="line">            WindowManagerGlobal.getWindowManagerService()</span><br><span class="line">                    .overridePendingAppTransitionRemote(runner, DEFAULT_DISPLAY);</span><br><span class="line">        &#125; <span class="keyword">catch</span> (Exception e) &#123;</span><br><span class="line">            Log.e(TAG, <span class="string">&quot;Error overriding screenshot app transition&quot;</span>, e);</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;, mMainExecutor);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>


      
      <blockquote>
        
        <strong>本文链接：</strong><br><a href="http://longzhiye.top/2024/02/10/2024-02-10/">http://longzhiye.top/2024/02/10/2024-02-10/</a>
      </blockquote>
    </div>
    <footer class="mdui-card-actions">
      
        <a class="mdui-ripple article_categories-link" href="/categories/%E6%8A%80%E6%9C%AF/">技术</a>
      
      
        <a class="mdui-ripple article_tags-link" href="/tags/Android/" rel="tag">Android</a><a class="mdui-ripple article_tags-link" href="/tags/SystemUI/" rel="tag">SystemUI</a><a class="mdui-ripple article_tags-link" href="/tags/framework/" rel="tag">framework</a>
      
    </footer>
    
  </article>
  
<script src="//cdn.bootcdn.net/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="//cdn.bootcdn.net/ajax/libs/fancybox/3.5.7/jquery.fancybox.min.js"></script>

  <script>$("#main article .mdui-card-content img.fancybox").on("click",function(e){$.fancybox.open({src:$(this).attr("src")});});</script>


  <nav id="paginator">
    
      <a rel="prev" class="extend prev" href="/2024/02/11/2024-02-11/">
        <button aria-label="prev" class="mdui-btn mdui-btn-raised mdui-btn-icon mdui-color-theme-accent mdui-ripple"><i class="mdui-icon material-icons">arrow_back</i></button>
        <span class="mdui-p-x-3" mdui-tooltip="{content: 'Android 14 录屏流程解析'}">上一篇</span>
      </a>
    
    <div class="spacer"></div>
    
      <a rel="next" class="extend next" href="/2024/02/03/2024-02-03/">
        <span class="mdui-p-x-3" mdui-tooltip="{content: 'Android SystemUI 通知面板实现'}">下一篇</span>
        <button aria-label="next" class="mdui-btn mdui-btn-raised mdui-btn-icon mdui-color-theme-accent mdui-ripple"><i class="mdui-icon material-icons">arrow_forward</i></button>
      </a>
    
  </nav>





</main>
  <footer id="footer" class="mdui-m-t-5 mdui-p-y-3 mdui-color-theme">
  <div class="mdui-p-y-0 mdui-text-center">
    
    
    
    
    
    
    
      <a href="http://github.com/longzhiye" target="_blank" class="mdui-btn mdui-btn-icon mdui-text-color-theme-a100"><i class="mdui-icon iconfont">&#xe7ab;</i></a>
    
    
    
      <a href="https://www.zhihu.com/people/long-zhi-xie-61" target="_blank" class="mdui-btn mdui-btn-icon mdui-text-color-theme-a100"><i class="mdui-icon iconfont">&#xe6c0;</i></a>
    
    
    
      <a href="tencent://tencent:////message/?uin=951898105&Menu=yes" target="_blank" class="mdui-btn mdui-btn-icon mdui-text-color-theme-a100"><i class="mdui-icon iconfont">&#xe651;</i></a>
    
    
  </div>
  <div class="mdui-p-y-1 mdui-text-center">
    Copyright &copy; 2022 - 2025 龙之叶<br>
    Powered by <a href="https://hexo.io/" target="_blank" class="mdui-text-color-theme-accent">Hexo</a>
    <br>
      <span id="busuanzi_container_site_pv" style="display: none;"><i class="iconfont">&#xe7fd;</i> <span id="busuanzi_value_site_pv"></span></span> &nbsp;&nbsp;
      <span id="busuanzi_container_site_uv" style="display: none;"><i class="iconfont">&#xe601;</i> <span id="busuanzi_value_site_uv"></span></span>
    
  </div>
</footer>

  <button id="gotop" class="mdui-fab mdui-fab-fixed mdui-fab-hide mdui-color-theme-accent mdui-ripple"><i class="mdui-icon material-icons">arrow_upward</i></button>
  <script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
  
<script src="/js/mdui.js"></script>
<script src="/js/script.js"></script>

  
<script src="/custom.js"></script>

</body>
</html>
